package com.metadata_system.common.enums;

import java.lang.reflect.Field;
import java.util.*;

public class AllConst {

    // 退换货允许退货时间(收货后)
    public final static String NoImageURL = "no-image.png";
    public final static String MemberGuestPassword = "b0BvPiSu1C";
//    public final static String OssURL = AliLiveUtils.OssUrl;
    public final static String OssURL = "http://192.168.3.6:7880/";

    public final static List<String> MetadataNodeHandleArr = Arrays.asList("left","right","bottom","top");
    public final static String EnableEdgeArrString = "{\"nodes\":[{\"id\":\"n1\",\"et\":0,\"type\":\"custom\",\"data\":{\"label\":\"依赖\",\"edgeType\":1,\"editFunction\":false,\"properties\":{\"short_name\":\"string\",\"keywords\":\"string\"}},\"position\":{\"x\":200,\"y\":100}},{\"id\":\"n2\",\"et\":0,\"type\":\"custom\",\"data\":{\"label\":\"关联\",\"edgeType\":4,\"editFunction\":false,\"properties\":{}},\"position\":{\"x\":200,\"y\":300}},{\"id\":\"n3\",\"et\":0,\"type\":\"custom\",\"data\":{\"label\":\"泛化\",\"edgeType\":8,\"editFunction\":false,\"properties\":{\"name\":\"string\",\"short_name\":\"string\",\"keywords\":\"string\",\"used_years\":\"int\",\"created_time\":\"string\"}},\"position\":{\"x\":200,\"y\":500}}],\"edges\":[{\"id\":\"e1\",\"et\":1,\"type\":\"custom\",\"data\":{\"label\":\"\",\"lineType\":\"step\",\"edgeType\":2,\"editFunction\":false,\"properties\":{\"name\":\"string\",\"short_name\":\"string\",\"keywords\":\"string\"},\"sourceHandle\":\"bottom\",\"targetHandle\":\"top\"},\"source\":\"n1\",\"target\":\"n2\"},{\"id\":\"e2\",\"et\":1,\"type\":\"custom\",\"data\":{\"label\":\"\",\"lineType\":\"step\",\"edgeType\":2,\"editFunction\":false,\"properties\":{\"name\":\"string\",\"short_name\":\"string\",\"keywords\":\"string\"},\"sourceHandle\":\"bottom\",\"targetHandle\":\"top\"},\"source\":\"n2\",\"target\":\"n3\"}]}";
    public final static String EnableNodeArrString = "[{\"id\":\"default\",\"et\":0,\"type\":\"custom\",\"data\":{\"label\":\"默认节点\",\"editFunction\":false,\"properties\":{}},\"position\":{\"x\":200,\"y\":500}}]";


    public final static List<String> DatabaseTypeList = Arrays.asList("通用数据库","项目数据库","个人数据库");
    public static Map<String, String> UploadFileTypeMap = new HashMap<>();
    public static Map<String, String> UserTypeMap = new HashMap<>();
    public static Map<String, String> UserRoleMap = new HashMap<>();
    public static Map<String, String> ProjectRoleMap = new HashMap<>();
    public static Map<String, String> AccessProviderUserRoleMap = new HashMap<>();

    public static List<String> UserStatusList = Arrays.asList("停用中", "启用中", "已锁定");
    public static List<String> ReadStatusList = Arrays.asList("未读", "已读");

    public static List<String> StatusArr = new ArrayList<>();
    public static List<String> UserStatusArr = new ArrayList<>();
    public static List<String> IsStatusArr = Arrays.asList("否", "是");
    public static List<String> ProjectLogStatusArr = Arrays.asList("待处理", "审核通过", "审核拒绝", "已取消");
    public static Map<String,String> ProjectLogTypeMap = new HashMap<String,String>(){{
        put("Import","项目数据-导入");
        put("Delete","项目数据-删除");
    }};

    public static Map<String,String> MessageTypeMap = new HashMap<String,String>(){{
        put("ProjectUser","项目成员-变动");
        put("ProjectApply","项目申请-更新");
        put("ProjectHandler","项目处理-更新");
    }};

    public static Map<String,String> UserOperationTypeMap = new HashMap<String,String>(){{
        put("User.Create","用户-创建");
        put("User.Update","用户-更新");
        put("User.Delete","用户-删除");
        put("User.ClearLoginDayError","用户-清除登录错误");

        put("Metadata.Create","元模型-创建");
        put("Metadata.Update","元模型-更新");
        put("Metadata.Delete","元模型-删除");

        put("MetadataView.Create","元模型-视图-创建");
        put("MetadataView.Update","元模型-视图-更新");
        put("MetadataView.Delete","元模型-视图-删除");

        put("MetadataNode.Create","元模型-节点-创建");
        put("MetadataNode.Update","元模型-节点-更新");
        put("MetadataNode.Delete","元模型-节点-删除");


        put("Database.Create","数据库-创建");
        put("Database.Update","数据库-更新");
        put("Database.Delete","数据库-删除");


        put("Project.Create","项目-创建");
        put("Project.Update","项目-更新");
        put("Project.Delete","项目-删除");

        put("ProjectNodeData.Insert","项目-数据-插入");
        put("ProjectNodeData.Delete","项目-数据-删除");
    }};

    public static List<String> LoginStatusArr = new ArrayList<>();

    public static List<String> SexArr = new ArrayList<>();

    static {

        UploadFileTypeMap.put("UserAvatar", "用户头像");
        UploadFileTypeMap.put("ImportProjectNodeData", "导入项目文件");

        AllConst.UserTypeMap.put("Admin", "系统用户");
        AllConst.UserTypeMap.put("AccessProviderUser", "接入商用户");

        AllConst.UserRoleMap.put("Super", "超级管理员");
        AllConst.UserRoleMap.put("System", "系统管理员");
        AllConst.UserRoleMap.put("User", "普通用户");

        AllConst.AccessProviderUserRoleMap.put("System", "系统管理员");
        AllConst.AccessProviderUserRoleMap.put("User", "普通用户");

        AllConst.ProjectRoleMap.put("Owner", "项目拥有者");
        AllConst.ProjectRoleMap.put("Editor", "项目数据员");


        AllConst.StatusArr.add("已禁用");
        AllConst.StatusArr.add("正常");

        AllConst.UserStatusArr.add("已禁用");
        AllConst.UserStatusArr.add("正常");
        AllConst.UserStatusArr.add("登录锁定");


        AllConst.LoginStatusArr.add("失败");
        AllConst.LoginStatusArr.add("成功");

        AllConst.SexArr.add("男");
        AllConst.SexArr.add("女");

    }

    public static Map<String, Object> EmptyIdName() {
        HashMap<String, Object> backMap = new HashMap<>();
        backMap.put("id", "");
        backMap.put("name", "");
        return backMap;
    }

    public static Map<String, Object> IdName(String key, Map<String, String> map) {
        HashMap<String, Object> backMap = new HashMap<>();
        backMap.put("id", key);
        backMap.put("name", map.get(key));
        return backMap;
    }

    public static Map<String, Object> IdName(String key, String value) {
        HashMap<String, Object> backMap = new HashMap<>();
        backMap.put("id", key);
        backMap.put("name", value);
        return backMap;
    }

    public static Map<String, Object> IdName(Integer key, List<String> list) {
        HashMap<String, Object> backMap = new HashMap<>();
        if (key == null) {
            return backMap;
        }
        backMap.put("id", key);
        backMap.put("name", list.get(key));
        return backMap;
    }
    public static HashMap<String, Object> KeyName(String key, Object name) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("key", key);
        map.put("name", name);
        return map;
    }

    /**
     * 获取类的所有静态字段（包括private，但不包括final）
     */
    public static Map<String, Object> getStaticFields(Class<?> clazz) throws IllegalAccessException {
        Map<String, Object> result = new HashMap<>();
        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {
            // 检查是否是静态字段
            if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
                field.setAccessible(true); // 设置可访问私有字段
                result.put(field.getName(), field.get(null)); // 静态字段传入null
            }
        }
        return result;
    }
}
